$(document).ready(
		function() {
			$('#loginModal').on('shown.bs.modal', function() {

				$('[name=username]').parent('div').removeClass('has-error');
				$('[name=password]').parent('div').removeClass('has-error');
				$('#login-name').focus();
			});
			$('#logout').click(function() {
				$.ajax({
					type : 'POST',
					url : '/cine-mtl/logout',
					success : function() {
						location.reload();
					},
					error : function(data) {
						console.log('error');
					}
				});
			});

			$('#submit').on(
					'click',
					function() {
						if ($('[name=username]').val() != ""
								&& $('[name=password]').val() != "") {
							var beforeEncrypt = $('[name=password]').val();
							if (beforeEncrypt != "") {
								var hash = CryptoJS.SHA1(beforeEncrypt);
								$('[name=password]').val(hash);
							}
							$.ajax({
								url : "login",
								type : "POST",
								data : 'username=' + $('[name=username]').val()
										+ "&password="
										+ $('[name=password]').val(),
								success : function(data) {
									// console.log(data);
									if (data == "invalid") {

										$('[name=username]').val('');
										$('[name=password]').val('');
										$('[name=username]').parent('div')
												.addClass('has-error');
										$('[name=password]').parent('div')
												.addClass('has-error');
									}
									else{
										$('#loginModal').modal('toggle');
										location.reload();
									}
								},
								error : function(data) {
									console.log('error');
								}
							});
						}
					});
			$('.btn-categorie').click(function() {
				var type = $(this).data('categorie');
				$.each($('.movieShowcase'), function() {
					if (type != 'all' && type != $(this).data('type')) {
						$(this).hide();
					} else {
						$(this).show();
					}

				});
			});

		});